package www.openteam.com.base;

import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.format.Time;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

import butterknife.ButterKnife;
import www.openteam.com.OTApplication;
import www.openteam.com.R;
import www.openteam.com.bean.CustomType;
import www.openteam.com.bean.DetailGather;
import www.openteam.com.bean.QueryCondition;
import www.openteam.com.mvp.IPresenter;
import www.openteam.com.mvp.IView;
import www.openteam.com.tool.ToastUtil;

/**
 * 带查询菜单类的Fragment
 * Created by kylin on 2016/12/13.
 */

public abstract class mBaseFragment<P extends IPresenter> extends Fragment
        implements SwipeRefreshLayout.OnRefreshListener, IView, View.OnClickListener {

    protected View view;
    //存储app各种数据
    public SharedPreferences mySetting = OTApplication.getmContext()
            .getSharedPreferences("mySetting", Context.MODE_PRIVATE);
    public SharedPreferences.Editor editor = mySetting.edit();
    protected P mPresenter;
    public static final int REQUEST_COUNT = 10;
    public DetailGather detailGather;   // 详细信息的枚举类
    public String[] detail;
    public SwipeRefreshLayout mSwipeRefresh;  //刷新布局
    public RecyclerView mRecyclerView;
    public QueryCondition queryCondition;
//    LinearLayout ll_mScroll;            //选项菜单
//    ImageView iv_arrow;                 //按钮
    float initial_y;                    //手指初始 y坐标
    float initial_h;                    //当前菜单初始长度
    int b = 0;                          //下拉时菜单高度变量
    private float FLING_MIN_DISTANCE = 50;  //手指滑动最小距离
    public LinearLayoutManager linearLayoutManager;
    EditText ed_4, ed_3;

    private int year;
    private int dayOfMonth;
    private int monthOfYear;
    private int syear;
    private int smonthOfYear;
    private int sdayOfMonth;
    public long currentMilli;
    public long startMilli;
    public long endMilli;
    private Context mContext;
    public ProgressDialog mProgressDialog;
    private int total_h;

    public boolean arrow_statue = true;
    public Animation animation;
    public float disY;
    public float a_disY;
    public float disMul;
    public GestureDetectorCompat gestureDetectorCompat;
    protected ArrayList<CustomType.DataBean> payTypesclass = new ArrayList<CustomType.DataBean>();
    protected ArrayList<CustomType.DataBean> moneyTypesclass = new ArrayList<CustomType.DataBean>();
    protected ArrayList<CustomType.DataBean> sendTypesclass = new ArrayList<CustomType.DataBean>();
    protected ArrayList<String> payTypes;
    protected ArrayList<String> moneryTypes;
    protected ArrayList<String> sendTypes;
    private String TAG = getClass().getSimpleName();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

//        getView(inflater, container);
        view = inflater.inflate(getLayoutId(), container, false);
//        ll_mScroll = (LinearLayout) view.findViewById(R.id.ll_mScroll);
//        iv_arrow = (ImageView) view.findViewById(R.id.iv_arrow);
//        iv_arrow.setOnTouchListener(new OptionMenuTouchListener());
        gestureDetectorCompat = new GestureDetectorCompat(getActivity(), new mBaseFragment.MyGestureDetector());
//        iv_arrow.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                gestureDetectorCompat.onTouchEvent(event);
//                return true;
//            }
//        });
        ButterKnife.bind(this, view);
        mPresenter = loadPresenter();
        initCommonData();
        initView();
        initListener();
        initData();
        initCalendar();

        return view;
    }


    private void initCommonData() {
        if (mPresenter != null)
            mPresenter.attachView(this);
        payTypesclass.add(new CustomType.DataBean("01", "20号月结，月结60天，23号收款"));
        payTypesclass.add(new CustomType.DataBean("02", "货到，验收后现金付款"));
        payTypesclass.add(new CustomType.DataBean("03", "25号月结，月结30天(寄付)"));
        payTypesclass.add(new CustomType.DataBean("04", "25号月结，月结60天"));
        payTypesclass.add(new CustomType.DataBean("05", "25号月结，月结90天"));
        payTypesclass.add(new CustomType.DataBean("06", "月底月结，月结60天，月底收款"));
        payTypesclass.add(new CustomType.DataBean("07", "23号月结，月结90天，23号收款"));
        payTypesclass.add(new CustomType.DataBean("08", "25号月结，月结105天，15号收款"));
        payTypesclass.add(new CustomType.DataBean("09", "25号月结，月结60天，月底收款"));
        payTypesclass.add(new CustomType.DataBean("10", "23号月结，月结150天，14号收款"));
        payTypes = new ArrayList<>();
        for (int i = 0; i < payTypesclass.size(); i++) {
            payTypes.add(payTypesclass.get(i).getName());
        }
        moneyTypesclass.add(new CustomType.DataBean("01", "RMB  人民币"));
        moneyTypesclass.add(new CustomType.DataBean("02", "HKD  港币"));
        moneyTypesclass.add(new CustomType.DataBean("03", "USD  美金"));
        moneyTypesclass.add(new CustomType.DataBean("04", "RMB  RMB"));
        moneyTypesclass.add(new CustomType.DataBean("06", "NTD  台币"));
        moneyTypesclass.add(new CustomType.DataBean("07", "EUR  欧元"));
        moneryTypes = new ArrayList<>();
        for (int i = 0; i < moneyTypesclass.size(); i++) {
            moneryTypes.add(moneyTypesclass.get(i).getName());
        }
        sendTypesclass.add(new CustomType.DataBean("01", "我厂送货"));
        sendTypesclass.add(new CustomType.DataBean("02", "货送我厂"));
        sendTypesclass.add(new CustomType.DataBean("03", "快递(寄付)"));
        sendTypesclass.add(new CustomType.DataBean("04", "快递(到付)"));
        sendTypesclass.add(new CustomType.DataBean("05", "委托货运公司送货"));
        sendTypesclass.add(new CustomType.DataBean("06", "委托货运公司上门提货"));
        sendTypesclass.add(new CustomType.DataBean("07", "客户上门自提"));
        sendTypesclass.add(new CustomType.DataBean("08", "我厂上门自提"));
        sendTypes = new ArrayList<>();
        for (int i = 0; i < sendTypesclass.size(); i++) {
            sendTypes.add(sendTypesclass.get(i).getName());
        }
    }

    protected abstract void initData();

    protected abstract void initListener();

    protected abstract void initView();

    protected abstract void otherViewClick(View view);


    protected abstract P loadPresenter();

    /**
     * @return 返回layout
     */
    public int getLayoutId() {
        Resources res = getResources();
        detail = res.getStringArray(detailGather.getResDetial());  //得到detailGather的所携带的string-array
        Log.e(TAG, "getLayoutId: " + detail.length);
        switch (detail.length) { //根据detail所包含string-arry的item数量选择需要的布局
            case 1:
//                return R.layout.fragment_detail1;
                return R.layout.fragment_detail1;
            case 2:
                return R.layout.fragment_detail2;
            case 3:
                if (detail[1].substring(detail[1].toString().length() - 3).equals("日期起")) {
                    Log.e(TAG, "getLayoutId: " + "fragment_detail3_2");
                    return R.layout.fragment_detail3_2;
                } else {
                    Log.e(TAG, "getLayoutId: " + "fragment_detail3");
                    return R.layout.fragment_detail3;
                }
            case 5:
                if (detail[2].toString().equals("单据状态")) {
                    Log.e(TAG, "getLayoutId: " + "fragment_detail5");
                    return R.layout.fragment_detail5;
                } else {
                    Log.e(TAG, "getLayoutId: " + "fragment_detail5_2");
                    return R.layout.fragment_detail5_2;
                }

            default:
                if (detail[1].toString().equals("单据状态")) {
                    Log.e(TAG, "getLayoutId: " + "fragment_detail4_2");
                    return R.layout.fragment_detail4_2;
                } else {
                    Log.e(TAG, "getLayoutId: " + "fragment_detail_text");
//                    return R.layout.fragment_detail;
                    return R.layout.fragment_detail_text;
                }

        }
    }


    /**
     * @return 显示的内容
     */
    public View getView(LayoutInflater inflater, ViewGroup container) {
        view = inflater.inflate(getLayoutId(), container, false);
//        ll_mScroll = (LinearLayout) view.findViewById(R.id.ll_mScroll);
//        iv_arrow = (ImageView) iv_arrow.findViewById(R.id.iv_arrow);
//        iv_arrow.setOnTouchListener(new OptionMenuTouchListener());

        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                otherViewClick(v);
                break;
        }
    }


    /**
     * 初始化日历时间
     */
    private void initCalendar() {
        Calendar calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        monthOfYear = calendar.get(Calendar.MONTH);
        dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        currentMilli = calendar.getTimeInMillis();
        Time time = new Time("GMT+8");
        time.setToNow();
        syear = time.year;
        smonthOfYear = time.month;
        sdayOfMonth = time.monthDay;
    }

    public void selectCalendar(final TextView v) {
        Calendar calendar = Calendar.getInstance();
        DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                v.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
            }
        }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
        datePickerDialog.show();
    }

    public void selectCalendarHMS(final TextView v) {
        final Calendar calendar = Calendar.getInstance();
        DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                //当前分
                int minute = calendar.get(Calendar.MINUTE);
                //当前秒
                int second = calendar.get(Calendar.SECOND);
                v.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " " + hour + ":" + minute + ":" + second);
            }
        }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
        datePickerDialog.show();
    }

    /**
     * 选择日期
     */
    public void selectCalendar() {

        DatePickerDialog datePickerDialog = new DatePickerDialog(OTApplication.getmContext(),
                new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear,
                                          int dayOfMonth) {

                        startMilli = changeMilli(year, monthOfYear, dayOfMonth);
//                Log.d(TAG, "onDateSet:"+startMilli+"....."+currentMilli);
                        if (startMilli > currentMilli) {
                            ToastUtil.showToast(getActivity(), "选择日期不能大于今日");
                            year = syear;
                            monthOfYear = smonthOfYear;
                            dayOfMonth = sdayOfMonth;
                            startMilli = currentMilli;
                        }

                        ed_4.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);

                    }

                }, year, monthOfYear, dayOfMonth);

        datePickerDialog.show();
//        Log.d("i","qqqq");
    }

    /**
     * 得到一周前的日期
     *
     * @return
     */
    public int get7Data() {
        Calendar c = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        int current_day = c.get(Calendar.DAY_OF_MONTH);
        int current_month = c.get(Calendar.MONTH);
        int current_year = c.get(Calendar.YEAR);
        c.set(current_year, current_month, current_day);
        c.add(Calendar.DATE, -7);
        Log.e(TAG, "get7Data: " + c.getTime().toString());
        return 0;
    }

    /**
     * 把选择的日期转换成毫秒数
     *
     * @param year  年
     * @param month 月
     * @param day   日
     * @return 毫秒数
     */
    protected long changeMilli(int year, int month, int day) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd", Locale.CHINA);
        String str = year + "-" + (month + 1) + "-" + day;
        long millionSeconds = 0;//毫秒
        try {
            millionSeconds = sdf.parse(str).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }

//        Log.d("今天", millionSeconds + "");
        return millionSeconds;
    }

    /**
     * 将str 日期转化成毫秒数
     *
     * @param str 日期
     * @return 毫秒数
     */
    public long changeMilli(String str) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd", Locale.ENGLISH);
        long millionSeconds = 0;//毫秒
        try {
            millionSeconds = sdf.parse(str).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }

//        Log.d("今天", millionSeconds + "");
        return millionSeconds;
    }

    /**
     * 选择结束的日期
     */
    public void selectEndCalendar() {

        DatePickerDialog datePickerDialog = new DatePickerDialog(OTApplication.getmContext(), new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                                  int dayOfMonth) {
//                Log.d("da",year+""+monthOfYear+dayOfMonth);
                endMilli = changeMilli(year, monthOfYear, dayOfMonth);
//                Log.d(TAG, "onDateSet:"+startMilli+"....."+currentMilli);

                if (endMilli > currentMilli) {
                    ToastUtil.showToast(getActivity(), "选择日期不能大于今日");
                    year = syear;
                    monthOfYear = smonthOfYear;
                    dayOfMonth = sdayOfMonth;
                }

                ed_3.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
            }

        }, year, monthOfYear, dayOfMonth);

        datePickerDialog.show();
//        Log.d("i","qqqq");
    }

    //初始化SwipRefresh 和 RecycleView
    public void initSRView(View view) {


        mSwipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_widget);
        mSwipeRefresh.setColorSchemeResources(R.color.colorPrimary, R.color.colorPrimaryDark, R.color.colorAccent);
        mSwipeRefresh.setOnRefreshListener(this);
        mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
        linearLayoutManager = new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(linearLayoutManager);

    }


    public void createProgressDialog(String content) {

        mContext = getContext();
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(mContext);
        }
        mProgressDialog.setMessage(content);
        mProgressDialog.show();


    }


    /**
     * 手势监听
     */
    public class MyGestureDetector extends GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

//            int top = (int) (disY - distanceY / 2);
//            int height = (int) (top + disY);
//            ll_mScorll.layout(0, -top, 0, height);
//            ToastUtil.showToast(getActivity(), "getY:" + e2.getY() + ",getRawY:" + e2.getRawY());
            return super.onScroll(e1, e2, distanceX, distanceY);
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//


            return super.onFling(e1, e2, velocityX, velocityY);
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
//            ToastUtil.showToast(getActivity(), "onSingleTapup");
            return super.onSingleTapUp(e);

        }

        @Override
        public void onLongPress(MotionEvent e) {
            super.onLongPress(e);

//            ToastUtil.showToast(getActivity(),"onLongPress" );
        }

        @Override
        public void onShowPress(MotionEvent e) {
            super.onShowPress(e);
//            ToastUtil.showToast(getActivity(),"onShowPress");
        }


        @Override
        public boolean onDown(MotionEvent e) {
//            ToastUtil.showToast(getActivity(),"onDown");

            return super.onDown(e);

        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {

//            ToastUtil.showToast(getActivity(),"onDoubleTap");
            return super.onDoubleTap(e);

        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {

            touchEvent();
            return super.onDoubleTapEvent(e);
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
//            ToastUtil.showToast(getActivity(),"onSingleTapConfirmed");
            return super.onSingleTapConfirmed(e);
        }

        @Override
        public boolean onContextClick(MotionEvent e) {
//            ToastUtil.showToast(getActivity(),"onContextClik");
            return super.onContextClick(e);
        }
    }


    /**
     * 动画
     */
    public class MyAnimationListenr implements Animation.AnimationListener {
        @Override
        public void onAnimationStart(Animation animation) {
//            if (arrow_statue) {
//                iv_arrow.setImageResource(R.drawable.icon_up_arrow);
//            } else {
//                iv_arrow.setImageResource(R.drawable.icon_down_arrow);
//            }
        }

        @Override
        public void onAnimationEnd(Animation animation) {
//            if (arrow_statue) {
//                ll_mScroll.setVisibility(View.GONE);
//
//            } else {
//                ll_mScroll.setVisibility(View.VISIBLE);
//            }
            arrow_statue = !arrow_statue;
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    }


    public Animation getArrowAnim(float a, float b, float c, float d, long time) {
        disMul = disY / a_disY;

        TranslateAnimation translateAnimation = new TranslateAnimation(a, b, c, d);
        translateAnimation.setDuration(time);
        return translateAnimation;

    }

    /**
     * 测量布局
     */
    public void measurementLayoutHeight() {
//        ViewTreeObserver vto = ll_mScroll.getViewTreeObserver();
//        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
//
//
//            @Override
//            public void onGlobalLayout() {
//                ll_mScroll.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//                disY = ll_mScroll.getHeight();
//            }
//        });
////        ViewTreeObserver vto_arr = iv_arrow.getViewTreeObserver();
//        vto_arr.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
//            @Override
//            public void onGlobalLayout() {
//                iv_arrow.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//
//                a_disY = iv_arrow.getHeight();
//            }
//        });


    }


    public void touchEvent() {
        if (arrow_statue) {
            animation = AnimationUtils.loadAnimation(
                    getActivity(), R.anim.ll_scroll_animation);
//            iv_arrow.startAnimation(animation);
//            ll_mScroll.startAnimation(animation);
            mSwipeRefresh.startAnimation(animation);

            animation.setAnimationListener(new mBaseFragment.MyAnimationListenr());

        } else {
            Animation ll_translatAnimation = getArrowAnim(0, 0, -disY, 0, 1500);
            Animation iv_translatAnimation = getArrowAnim(0, 0, 0, disY, 1500);
//            ll_mScroll.startAnimation(ll_translatAnimation);
//            iv_arrow.startAnimation(iv_translatAnimation);
            mSwipeRefresh.startAnimation(iv_translatAnimation);
            iv_translatAnimation.setAnimationListener(new mBaseFragment.MyAnimationListenr());
        }
    }


    //    /**
//     * 自定义的选项菜单触摸监听
//     */
//    class OptionMenuTouchListener implements View.OnTouchListener {
//
//        private float variable;
//
//        @Override
//        public boolean onTouch(View v, MotionEvent event) {
//
//            switch (event.getAction()) {
//                case MotionEvent.ACTION_DOWN:
//                    initial_y = event.getRawY();
//                    initial_h = ll_mScroll.getHeight();
//                    total_h = iv_arrow.getHeight() + ll_mScroll.getHeight();
//                    break;
//                case MotionEvent.ACTION_MOVE:
//                    variable = Math.abs(event.getRawY() - initial_y);
//                    if (Math.abs(event.getRawY() - initial_y) > FLING_MIN_DISTANCE
//                            ) {
//                        int y_var = (int) -(event.getRawY() - initial_y);
//                        int width = ll_mScroll.getWidth();
//                        int height = ll_mScroll.getHeight();
//                        int ll_position = height - y_var;
//                        if (arrow_statue) {
//                            // 左 上 右 下
//                            ll_mScroll.layout(0, 0, width, ll_position);
//                        } else {
//                            b += (-y_var);
//                            ll_mScroll.layout(0, 0, width, b);
//                        }
//                        int itop = ll_position;
//                        int ibottom = ll_position + iv_arrow.getHeight();
//                        if (itop < 0) {
//                            itop = 0;
//                            ibottom = iv_arrow.getHeight();
//                        }
//                        iv_arrow.layout((int) iv_arrow.getX(), itop,
//                                (int) (iv_arrow.getX() + iv_arrow.getWidth()),
//                                ibottom);
//                        initial_y = event.getRawY();
//                    }
//                    break;
//                case MotionEvent.ACTION_UP:
//                    float now_h = ll_mScroll.getHeight();
//                    if (arrow_statue && now_h < initial_h / 2 && now_h >= 0) {
//
//                        Animation ll_translatAnimation = getArrowAnim(0, 0, 0, -now_h, 200);
//                        Animation iv_translatAnimation = getArrowAnim(0, 0, 0, -now_h, 200);
//                        ll_mScroll.startAnimation(ll_translatAnimation);
//                        iv_arrow.startAnimation(iv_translatAnimation);
//                        ll_mScroll.layout(0, (int) (-initial_h), ll_mScroll.getWidth(), 0);
//                        iv_arrow.layout((int) iv_arrow.getX(), 0,
//                                (int) (iv_arrow.getX() + iv_arrow.getWidth()),
//                                iv_arrow.getHeight());
//                        ll_mScroll.clearAnimation();
//                        iv_arrow.clearAnimation();
//                        arrow_statue = !arrow_statue;
//                    } else if (!arrow_statue && now_h > initial_h / 2) {
//                        ll_mScroll.layout(0, 0, ll_mScroll.getWidth(), (int) initial_h);
//                        iv_arrow.layout((int) iv_arrow.getX(), (int) initial_h,
//                                (int) (iv_arrow.getX() + iv_arrow.getWidth()),
//                                iv_arrow.getHeight() + (int) initial_h);
//                        arrow_statue = !arrow_statue;
//                        b = 0;
//                    } else if (arrow_statue && now_h >= initial_h / 2) {
//                        ll_mScroll.layout(0, 0, ll_mScroll.getWidth(), (int) initial_h);
//                        iv_arrow.layout((int) iv_arrow.getX(), (int) initial_h,
//                                (int) (iv_arrow.getX() + iv_arrow.getWidth()),
//                                iv_arrow.getHeight() + (int) initial_h);
//                    } else if (!arrow_statue && now_h < initial_h / 2) {
//
//                        ll_mScroll.layout(0, -(int) (initial_h), ll_mScroll.getWidth(), 0);
//                        iv_arrow.layout((int) iv_arrow.getX(), 0,
//                                (int) (iv_arrow.getX() + iv_arrow.getWidth()),
//                                iv_arrow.getHeight());
//                        b = 0;
//                    }
//                    break;
//            }
//            return false;
//        }
//    }
//
//
//    private Animation getArrowAnim(float a, float b, float c, float d, long time) {
//
//        TranslateAnimation translateAnimation = new TranslateAnimation(a, b, c, d);
//        translateAnimation.setDuration(time);
//        return translateAnimation;
//
//    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null)
            mPresenter.detachView();
    }

}
